<!-- <template>
    <h1>这是登录页面</h1>

    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="info.UL_Name" placeholder="请输入用户名">
            </td>
        </tr>
        
        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="info.UL_Pwd" placeholder="请输入密码">
            </td>
        </tr>
        
        <tr>
            <td colspan="2">
                <input type="button" value="登录" @click="Login">
            </td>
        </tr>
    </table>

</template>

<script setup lang="ts">
import axios from 'axios'
import {ref} from 'vue'
import {useRouter} from 'vue-router'
import {useStore} from '../../store/index.ts'

//创建仓库实例
const store = useStore();

//获取路由实例
const router = useRouter();

const info = ref({
    UL_Name:"",
    UL_Pwd:""
})

const Login =() =>{
    if(info.value.UL_Name==""){
        alert("用户名称不能为空");
        return;
    }
    if(info.value.UL_Pwd==""){
        alert("密码不能为空");
        return;
    }
    //console.log(info.value.UL_Name)
    //console.log(info.value.UL_Pwd)
    axios({
        url:"http://localhost:53279/api/User/UserLogin",
        method:"get",
        params:{
            Uname:info.value.UL_Name,
            Upwd:info.value.UL_Pwd
        }
    })
    .then(function(res){
        console.log(res.data);
        if(res.data.RM_Id==0){
            console.log(res.data.RM_Data[0].U_Id);
            alert(res.data.RM_Msg);//登录成功的提示信息
            
            console.log(res);
            //将用户编号存入仓库
            store.UserId = res.data.RM_Data[0].U_Id;
            
            //验证用户是否完善用户详细信息
            ServerUserInfo(res.data.RM_Data[0].U_Id);
        }
        else if(res.data.RM_Id==1){
            alert(res.data.RM_Msg);//用户不存在的提示信息
            return;
        }
        else if(res.data.RM_Id==2){
            alert(res.data.RM_Msg);//账号密码不匹配的提示信息
            return;
        }
        else{
            alert("登录失败");
            return;
        }
    })
    .catch(function(err){
        console.log(err);
    })
}

//检查用户是否完善用户详细信息
const ServerUserInfo = (Uid:string) =>{
    axios({
        url:"http://localhost:53279/api/User/ServerUserInfo",
        method:"get",
        params:{
            Uid:Uid
        }
    })
    .then(function(res){
        if(res.data>0){
            alert("用户个人信息已完善,即将跳转到主页面");
            router.push('/UserFinancingShow')
        }
        else{
            router.push({
                name:"UserInfoRegister",
                params:{
                    Uid:Uid
                }
            })
        }
    })
}


</script> -->

<template>
    <html lang="en">
<div class="pure-g content">
	<div class="pure-form pure-u-1" >
        <h4>请登录您的账号</h4>
        <fieldset class="pure-group">
            <input type="text" class="pure-input-1" v-model="info.UL_Name" placeholder="用户名" required autofocus>
            <input type="password" class="pure-input-1" v-model="info.UL_Pwd" placeholder="密　码" required>
        </fieldset>
        <button class="pure-button pure-u-1 pure-button-primary" @click="Login" type="submit">登　录</button>
	</div>
</div>
<div class="pure-g copyright">
    <div class="pure-u-1"> 2024 WLW-XTY. </div>
</div>

</html>
</template>

<script setup lang="ts">
import axios from 'axios'
import {ref} from 'vue'
import {useRouter} from 'vue-router'
import {useStore} from '../../store/index.ts'

//创建仓库实例
const store = useStore();

//获取路由实例
const router = useRouter();

const info = ref({
    UL_Name:"",
    UL_Pwd:""
})

const Login =() =>{
    if(info.value.UL_Name==""){
        alert("用户名称不能为空");
        return;
    }
    if(info.value.UL_Pwd==""){
        alert("密码不能为空");
        return;
    }
    //console.log(info.value.UL_Name)
    //console.log(info.value.UL_Pwd)
    axios({
        url:"http://localhost:53279/api/User/UserLogin",
        method:"get",
        params:{
            Uname:info.value.UL_Name,
            Upwd:info.value.UL_Pwd
        }
    })
    .then(function(res){
        console.log(res.data);
        if(res.data.RM_Id==0){
            console.log(res.data.RM_Data[0].U_Id);
            alert(res.data.RM_Msg);//登录成功的提示信息
            
            console.log(res);
            //将用户编号存入仓库
            store.UserId = res.data.RM_Data[0].U_Id;
            
            //验证用户是否完善用户详细信息
            ServerUserInfo(res.data.RM_Data[0].U_Id);
        }
        else if(res.data.RM_Id==1){
            alert(res.data.RM_Msg);//用户不存在的提示信息
            return;
        }
        else if(res.data.RM_Id==2){
            alert(res.data.RM_Msg);//账号密码不匹配的提示信息
            return;
        }
        else{
            alert("登录失败");
            return;
        }
    })
    .catch(function(err){
        console.log(err);
    })
}

//检查用户是否完善用户详细信息
const ServerUserInfo = (Uid:string) =>{
    axios({
        url:"http://localhost:53279/api/User/ServerUserInfo",
        method:"get",
        params:{
            Uid:Uid
        }
    })
    .then(function(res){
        if(res.data>0){
            alert("用户个人信息已完善,即将跳转到主页面");
            router.push('/ShowAllInversRedeer')
        }
        else{
            router.push({
                name:"UserInfoRegister",
                params:{
                    Uid:Uid
                }
            })
        }
    })
}
</script>
